﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Aeon.Presentation.Debugger"
                    xmlns:dbg="clr-namespace:Aeon.Emulator.DebugSupport;assembly=Aeon.Emulator">
    <ControlTemplate x:Key="miniExpanderButtonTemplate" TargetType="{x:Type CheckBox}">
        <Border Name="border" Width="12" Height="12" BorderThickness="1" BorderBrush="Black" Background="Transparent" Margin="2" CornerRadius="2">
            <Grid>
                <Rectangle Name="horizontalLine" StrokeThickness="0" Fill="Black" Width="8" Height="2" VerticalAlignment="Center" />
                <Rectangle Name="verticalLine" StrokeThickness="0" Fill="Black" Width="2" Height="8" HorizontalAlignment="Center" Visibility="Collapsed" />
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="False">
                <Setter TargetName="verticalLine" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="horizontalLine" Property="Fill" Value="Blue" />
                <Setter TargetName="verticalLine" Property="Fill" Value="Blue" />
                <Setter TargetName="border" Property="Background" Value="Gainsboro" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <DataTemplate x:Key="instructionTemplate" DataType="{x:Type dbg:Instruction}">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding CS, StringFormat={}{0:X4}:}" />
            <TextBlock Text="{Binding EIP, StringFormat={}{0:X8}}" Margin="0,0,20,0" />
            <TextBlock Text="{Binding Opcode.Name}" />
            <TextBlock Text=" " />
            <local:OperandDisplay Operand="{Binding Operands.Operand1}" Instruction="{Binding}" />
            <TextBlock Name="comma1" Text=", " Visibility="Collapsed" />
            <local:OperandDisplay Operand="{Binding Operands.Operand2}" Instruction="{Binding}" />
            <TextBlock Name="comma2" Text=", " Visibility="Collapsed" />
            <local:OperandDisplay Operand="{Binding Operands.Operand3}" Instruction="{Binding}" />
        </StackPanel>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Opcode.Operands.Count}" Value="2">
                <Setter TargetName="comma1" Property="Visibility" Value="Visible" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Opcode.Operands.Count}" Value="3">
                <Setter TargetName="comma1" Property="Visibility" Value="Visible" />
                <Setter TargetName="comma2" Property="Visibility" Value="Visible" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate x:Key="loggedInstructionTemplate" DataType="{x:Type dbg:LoggedInstruction}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <CheckBox Name="expandCheckBox" Template="{StaticResource miniExpanderButtonTemplate}" />
            <StackPanel Grid.Column="1" Orientation="Horizontal">
                <TextBlock Text="{Binding CS, StringFormat={}{0:X4}:}" />
                <TextBlock Text="{Binding EIP, StringFormat={}{0:X8}}" Margin="0,0,20,0" />
                <TextBlock Text="{Binding Opcode.Name}" />
                <TextBlock Text=" " />
                <local:OperandDisplay Operand="{Binding Operands.Operand1}" Instruction="{Binding}" />
                <TextBlock Name="comma1" Text=", " Visibility="Collapsed" />
                <local:OperandDisplay Operand="{Binding Operands.Operand2}" Instruction="{Binding}" />
                <TextBlock Name="comma2" Text=", " Visibility="Collapsed" />
                <local:OperandDisplay Operand="{Binding Operands.Operand3}" Instruction="{Binding}" />
            </StackPanel>
            <local:RegisterViewer x:Name="registerViewer" Grid.Column="1" Grid.Row="1" RegisterSource="{Binding}" />
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Opcode.Operands.Count}" Value="2">
                <Setter TargetName="comma1" Property="Visibility" Value="Visible" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Opcode.Operands.Count}" Value="3">
                <Setter TargetName="comma1" Property="Visibility" Value="Visible" />
                <Setter TargetName="comma2" Property="Visibility" Value="Visible" />
            </DataTrigger>
            <Trigger SourceName="expandCheckBox" Property="IsChecked" Value="False">
                <Setter TargetName="registerViewer" Property="Visibility" Value="Collapsed" />
            </Trigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    
    <local:InstructionTemplateSelector x:Key="instructionTemplateSelector" />

</ResourceDictionary>